/**
 * @file: vscode
 * @author: v_xieyejiang
 * @Date: 2018-12-10 11:24:08
 * @Last Modified by: v_xieyejiang
 * @Last Modified time: 2018-12-10 11:25:07
 */

import {utilsAxios} from '@/utils';
import hello from '@/services/node/hello';
import * as types from '@/store/mutation-types';

export default {
    namespaced: true,
    state: {
        hello: {
            get: '',
            post: ''
        }
    },
    getters: {
        hello: State => State.hello
    },
    actions: {
        // hello
        async getHello({commit}, options) {
            const result = await hello.getHello(options && options.data);
            utilsAxios(options, result);
            if (result && result.data && result.data.data) {
                commit(types.GETHELLO, result.data.data);
            }
        },
        // hello
        async postHello({commit}, options) {
            const result = await hello.postHello(options && options.data);
            utilsAxios(options, result);
            if (result && result.data && result.data.data) {
                commit(types.POSTHELLO, result.data.data);
            }
        }
    },
    mutations: {
        [types.GETHELLO](State, data) {
            State.hello.get = data.message;
        },
        [types.POSTHELLO](State, data) {
            State.hello.post = data.message;
        }
    }
};
